<script>
	export default {
		onLaunch: function() {
			
			
			
			console.log('App Launch')
			let version = uni.getSystemInfoSync().appVersion;
			console.log(
				`%c 派箱箱 %c 当前版本号 v${version} %c`,
				'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px;  color: #fff',
				'background:#007aff ;padding: 1px; border-radius: 0 3px 3px 0;  color: #fff; font-weight: bold;',
				'background:transparent'
			)
			// #ifdef H5
			uni.getSystemInfo({
				success: (info) => {
					console.log(info);
					let { osName,osVersion } = info;
					osVersion = osVersion.substring(0,2);
					console.log("osName: ",osName);
					console.log("osVersion: ",osVersion);
					if(osName=='android'){
						uni.setStorageSync('isIos',false);
					}else{
						uni.setStorageSync('isIos',true);
					}
				}
			})
			// #endif
			// #ifdef APP-PLUS
			const deviceId = uni.getSystemInfoSync().deviceId;
			const deviceBrand = uni.getSystemInfoSync().deviceBrand;
			//获取设备的唯一标识
			let clientId = '';
			let deviceType = '';
			plus.device.getOAID({
				success: (e) => {
					clientId = e.oaid;
					deviceType = 'oaid';
					console.log("clientId: ",clientId);
					console.log("deviceType: ",deviceType);
					if(!clientId || clientId == '00000000-0000-0000-0000-000000000000'){
						plus.device.getInfo({
							success: (e) => {
								clientId = e.uuid;
								deviceType = 'imei';
								console.log("clientId: ",clientId);
								console.log("deviceType: ",deviceType);
							},
							fail: (e) => {
								console.log(e);
							}
						});
					}
				},
				fail: (e) => {
					console.log(e);
				}
			});
			plus.navigator.closeSplashscreen();
			// const jyJPush = uni.requireNativePlugin('JY-JPushThird');
			uni.getSystemInfo({
				success: (info) => {
					console.log(info);
					let osName = info.osName;
					let osVersion = info.osVersion.substring(0,2);
					if(osName=='android'){
						jyJPush.android_init(res=> {
							console.log(res,'android_init');
						})
					}else{
						if(osVersion >= 13){
							uni.setStorageSync('isIos',true);
						}
						// 判断第三方程序(微信) 是否安装
						if(plus.runtime.isApplicationExist({action:'weixin://'})){
							console.log("微信应用已安装");
							uni.setStorageSync('isExistWx',true);
						}else{
							console.log("微信应用未安装");
							uni.setStorageSync('isExistWx',false);
						}
					}
				}
			})
			jyJPush.setJYJPushAlias({
				userAlias: deviceId
			}, result=> {
				console.log(result,'userAlias');
			});
			this.$api.vivoopen({
				device_id :deviceId,
				brand:deviceBrand,
				device_type:deviceType,
				device_unicode:clientId
			}).then(openres=>{
				console.log("openres: ",openres);
			})
			//监听消息通知事件（后台发送后，会触发）
			jyJPush.addJYJPushReceiveNotificationListener(result=> {
				uni.showModal({
					title:JSON.parse(result).n_title,
					content:JSON.parse(result).n_content,
					showCancel:false
				})
				console.log(JSON.parse(result),'watchPush');
			});
			//监听点击通知栏消息事件(点击通知栏的消息，或者悬浮框，会触发；跳转需要用到)
			jyJPush.addJYJPushReceiveOpenNotificationListener(result=> {
				if(result.msg!='无数据'){
					let page = JSON.parse(result).n_extras.page;
					uni.switchTab({
						url:page
					})
					uni.showModal({
						title:JSON.parse(result).n_title,
						content:JSON.parse(result).n_content,
						showCancel:false,
					})
				console.log(JSON.parse(result),'watchClick');
				}
			})
			//监听消息点击事件（APP进程被杀死后，消息还存在通知栏的时候，点击消息会出触发这个方法）
			setTimeout(()=>{
				jyJPush.getLastPushInfo(result => {
					uni.showModal({
						title:JSON.parse(result.data.lastPush).n_title,
						content:JSON.parse(result.data.lastPush).n_content,
						showCancel:false
					})
					console.log(JSON.parse(result.data.lastPush),'watchLastPush');
				})
			},2000)
			//监听自定义消息（穿透消息）
			jyJPush.addJYJPushCustomReceiveNotificationListener(result => {
				uni.showModal({
					title:JSON.parse(result.lastPush).n_title,
					content:JSON.parse(result.lastPush).n_content,
					showCancel:false
				})
				console.log(JSON.parse(result),'watchCustom');
			});
			//#endif
			// //安卓检查是否开启通知权限
			// jyJPush.android_isNotificationEnabled(result=> {
			// 	/*
			// 	status = 0，关闭
			// 	status = 1, 开启
			// 	status = -1, 检测失败
			// 	*/
			// 	console.log(JSON.stringify(result));
			// });
			//安卓打开通知权限设置页面（系统的页面）
			// jyJPush.android_goToAppNotificationSettings(result=> {
			// 	console.log(JSON.stringify(result));
			// });
			//iOS请求通知权限（可作为检测是否打开通知权限的API）
			// jyJPush.ios_requestNotificationAuthorization(result=> {
			// 	/*
			// 	status = 0，用户尚未对该应用的权限做出选择
			// 	status = 1, 被关闭了权限
			// 	status = 2, 开启了权限
			// 	status = 3, 开启了非中断用户通知权限，iOS12支持
			// 	*/
			// 	console.log(JSON.stringify(result));
			// });
			//iOS打开通知权限设置页面（系统的页面）
			// jyJPush.ios_openSettingsForNotification(result=> {
			// 	console.log(JSON.stringify(result));
			// });
			//设置手机号码
			// jyJPush.setMobileNumber({
			// 	mobileNumber: '13281055555'
			// }, res=> {})
		},
		onShow: function() {
			console.log('App Show')
			// #ifdef APP-PLUS
			let args = plus.runtime.arguments;
			let auth_code = '';
			if(args != ''){
				try{
					auth_code = JSON.parse(args).auth_code;
					plus.runtime.arguments = null;
					if(auth_code != '' && auth_code!=undefined){
						uni.redirectTo({
							url:`/pages/mine/setup/setup_userinfo?auth_code=${auth_code}`
						})
					}
					
				}catch(e){
					auth_code = args.split('auth_code=')[1];
					plus.runtime.arguments = null;
					if(auth_code != '' && auth_code!=undefined){
						uni.redirectTo({
							url:`/pages/mine/setup/setup_userinfo?auth_code=${auth_code}`
						})
					}
				}
			}
			// #endif
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
	page{
		background-color: $page;
	}
	
	.status_bar {  
		width: 100%;
	    height: var(--status-bar-height);  
		background-color: #0c359c;
	    position: fixed;
	    top: 0;  
	    z-index: 999;  
	} 
	uni-modal{
		z-index: 99999;
	}
</style>
